using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class DIC_SALARY_STEPData : DatabaseObjectBase
	{
		public DIC_SALARY_STEPData()
		{
			Initialize(true);
		}
		public DIC_SALARY_STEPData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 DIC_SALARY_STEP_Insert(Int32 StepCode, String RankCode, String StepName, Double Coefficient, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("DIC_SALARY_STEP_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@StepCode", SqlDbType.Int));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@StepName", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Coefficient", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Prepare();
				SqlInt32 StepCodeSQL = StepCode;
				_dbadapter.InsertCommand.Parameters["@StepCode"].Value = StepCodeSQL;
				SqlString RankCodeSQL = RankCode;
				_dbadapter.InsertCommand.Parameters["@RankCode"].Value = RankCodeSQL;
				SqlString StepNameSQL = StepName;
				_dbadapter.InsertCommand.Parameters["@StepName"].Value = StepNameSQL;
				SqlDouble CoefficientSQL = Coefficient;
				_dbadapter.InsertCommand.Parameters["@Coefficient"].Value = CoefficientSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: DIC_SALARY_STEP_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: DIC_SALARY_STEP_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 DIC_SALARY_STEP_Update(Int32 StepCode, String RankCode, String StepName, Double Coefficient, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("DIC_SALARY_STEP_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@StepCode", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@StepName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Coefficient", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlInt32 StepCodeSQL = StepCode;
				_dbadapter.UpdateCommand.Parameters["@StepCode"].Value = StepCodeSQL;
				SqlString RankCodeSQL = RankCode;
				_dbadapter.UpdateCommand.Parameters["@RankCode"].Value = RankCodeSQL;
				SqlString StepNameSQL = StepName;
				_dbadapter.UpdateCommand.Parameters["@StepName"].Value = StepNameSQL;
				SqlDouble CoefficientSQL = Coefficient;
				_dbadapter.UpdateCommand.Parameters["@Coefficient"].Value = CoefficientSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: DIC_SALARY_STEP_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: DIC_SALARY_STEP_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 DIC_SALARY_STEP_Disable(Int32 StepCode, String RankCode, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("DIC_SALARY_STEP_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@StepCode", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlInt32 StepCodeSQL = StepCode;
				_dbadapter.UpdateCommand.Parameters["@StepCode"].Value = StepCodeSQL;
				SqlString RankCodeSQL = RankCode;
				_dbadapter.UpdateCommand.Parameters["@RankCode"].Value = RankCodeSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: DIC_SALARY_STEP_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: DIC_SALARY_STEP_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 DIC_SALARY_STEP_Delete(Int32 StepCode, String RankCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("DIC_SALARY_STEP_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@StepCode", SqlDbType.Int));
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
				_dbadapter.DeleteCommand.Prepare();
				SqlInt32 StepCodeSQL = StepCode;
				_dbadapter.DeleteCommand.Parameters["@StepCode"].Value = StepCodeSQL;
				SqlString RankCodeSQL = RankCode;
				_dbadapter.DeleteCommand.Parameters["@RankCode"].Value = RankCodeSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: DIC_SALARY_STEP_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: DIC_SALARY_STEP_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 DIC_SALARY_STEP_Save(Int32 StepCode, String RankCode, String StepName, Double Coefficient, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("DIC_SALARY_STEP_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@StepCode", SqlDbType.Int));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@StepName", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Coefficient", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlInt32 StepCodeSQL = StepCode;
				_dbadapter.UpdateCommand.Parameters["@StepCode"].Value = StepCodeSQL;
				SqlString RankCodeSQL = RankCode;
				_dbadapter.UpdateCommand.Parameters["@RankCode"].Value = RankCodeSQL;
				SqlString StepNameSQL = StepName;
				_dbadapter.UpdateCommand.Parameters["@StepName"].Value = StepNameSQL;
				SqlDouble CoefficientSQL = Coefficient;
				_dbadapter.UpdateCommand.Parameters["@Coefficient"].Value = CoefficientSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: DIC_SALARY_STEP_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: DIC_SALARY_STEP_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet DIC_SALARY_STEP_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("DIC_SALARY_STEP_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: DIC_SALARY_STEP_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet DIC_SALARY_STEP_Get(Int32 StepCode, String RankCode)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("DIC_SALARY_STEP_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@StepCode", SqlDbType.Int));
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
				_dbadapter.SelectCommand.Prepare();
				SqlInt32 StepCodeSQL = StepCode;
				_dbadapter.SelectCommand.Parameters["@StepCode"].Value = StepCodeSQL;
				SqlString RankCodeSQL = RankCode;
				_dbadapter.SelectCommand.Parameters["@RankCode"].Value = RankCodeSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: DIC_SALARY_STEP_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
        public DataSet DIC_SALARY_STEP_GetListByRank(String RankCode)
        {
            try
            {
                if (_dbconn.State != ConnectionState.Open)
                    _dbconn.Open();
                _dbadapter.SelectCommand = new SqlCommand("DIC_SALARY_STEP_GetListByRank");
                _dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                _dbadapter.SelectCommand.Connection = _dbconn;
                _dbadapter.SelectCommand.Parameters.Clear();
                _dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@RankCode", SqlDbType.VarChar, 20));
                _dbadapter.SelectCommand.Prepare();
                SqlString RankCodeSQL = RankCode;
                _dbadapter.SelectCommand.Parameters["@RankCode"].Value = RankCodeSQL;
                _dbadapter.Fill(_data);

                return _data;
            }
            catch (SqlException e)
            {
                throw new Exception("SQL Error: DIC_SALARY_STEP_GetListByRank: " + e.Message, e);
            }
            finally
            {
                if (_dbadapter.SelectCommand != null)
                    _dbadapter.SelectCommand.Dispose();
                CloseConnection();
            }
        }
	}
}
